/*KaisarCode Tools v1.0 by kaisarcode.com

http://code.google.com/p/kaisarcode-tools/

Licensed under GNU LGPL. http://www.gnu.org/licenses/lgpl.html
*/
(function(){
	
	//==LAUNCHER METHOD==//
	kc=function(a,b){
		var output={};
		kc.dump.dataType=kc.dataType(a);
		kc.dump.constructorType=kc.constructorType(a);
		kc.dump.query=a;
		kc.dump.filter=b;
		kc.dump.event=kc.ev(a);
		if(kc.dump.query!==undefined){
			if(kc.dump.dataType=="String") output=new String(a);
			if(kc.dump.dataType=="Number") output=new Number(a);
			if(kc.dump.dataType=="RegExp") output=new RegExp(a);
		}
		for(var c in kc.proto){
			if(kc.constructorType(kc.proto[c])=="Function"){
				output[c]=kc.proto[c];
			}else{
				for(var d in kc.proto[c]){
					if(kc.dump.dataType.toLowerCase()===c || kc.dump.constructorType.toLowerCase()===c){
						output[d]=kc.proto[c][d];
				}}
				if(kc.dump.event){
					for(var e in kc.proto.event){
						output[e]=kc.proto.event[e];
		}}}}
		output.dataType=kc.dump.dataType;
		output.constructorType=kc.dump.constructorType;
		output.query=a;
		output.filter=b;
		return output;
	}
	//===Default collections===//
	kc.dump={
		dataType:undefined,
		constructorType:undefined,
		query:undefined,
		filter:undefined,
		event:undefined
	}
	kc.proto={}
	
	//===STAND ALONE METHODS==//
	
	//==Constructor Type==//
	kc.dataType=function(a){
		var output=null;
		if(a===undefined) return "Undefined";
		if(a===null) return "Null";
		if(a===NaN) return "NaN";
		if(a.constructor){
			try{
				output=a.constructor.toString().split("function ")[1].split("(")[0];
			}catch(err){
				output=a.constructor.toString().split(" ")[1].split("]")[0];
			}
		}
		return output;
	}
	//==Datatype==//
	kc.constructorType=function(a){
		if(a===undefined) return "Undefined";
		if(a===null) return "Null";
		if(a===NaN) return "NaN";
		if(a.constructor){ 
			if(a.constructor.toString().toLowerCase().match("event")) return "Event";
			if(a.constructor.toString().toLowerCase().match("object")) return "Object";
			if(a.constructor.toString().toLowerCase().match("function")) return "Function";
		}
	}
	
	//==KAISARCODE TOOLS MULTI EXTENSION==//
	kc.extend=function(a,b){
		var group=new Array();
		if(kc.dataType(a)=="Array") group=a;
		if(kc.dataType(a)=="String") group[0]=a;
		if(kc.dataType(b)=="Object")
			for(var c=0;c<group.length;c++){
				if(!kc.proto[group[c]]) kc.proto[group[c]]={};
				for(var d in b) kc.proto[group[c]][d]=b[d];
	}}
	
	//==Location==//
	kc.location={
		href:location.href,
		hash:location.hash,
		host:location.host,
		hostname:location.hostname,
		path:location.pathname,
		port:location.port,
		protocol:location.protocol,
		search:location.search
	}
	
	kc.location.vars={};
	if(location.search){
		var searchquery=location.search.substring(1).split("&");
		var splittedvars;
		for(var kci=0;kci<searchquery.length;kci++){
			splittedvars=searchquery[kci].split("=");
			kc.location.vars[splittedvars[0]]=splittedvars[1];
	}}
	
	//Normalized event object
	kc.ev=function(e){
		if(!e) var e=window.event;
		if(e===null) e=undefined;
		return e;
	}
	
	
	//===DEPENDANT METHODS===//
	//==STRING==//
	kc.proto.string={
		//Remove white spaces at the beginning and the end of the string
		trim:function(){
			return kc.dump.query.replace(/^\s+|\s+$/g,'');
		},
		//Parse XML from kc.dump.query
		toXML:function(){
			var kc_xml;
			var kc_parser;
			if(window.DOMParser){
				kc_parser=new DOMParser();
				kc_xml=kc_parser.parseFromString(kc.dump.query,"text/xml");
			}else{
				kc_xml=new ActiveXObject("Microsoft.XMLDOM");
				kc_xml.loadXML(kc.dump.query);
			}
			return kc_xml;
		},
		//Parse string as JavaScript
		toJS:function(){
			eval(kc.dump.query);
		},
		//Decode URI
		decodeURI:function(){
			return decodeURI(kc.dump.query);
		},
		//Decode URI Component
		decodeURIComponent:function(){
			return decodeURIComponent(kc.dump.query);
		},
		//Encode URI
		encodeURI:function(){
			return encodeURI(kc.dump.query);
		},
		//Encode URI Component
		encodeURIComponent:function(){
			return encodeURIComponent(kc.dump.query);
		},
		//Escape a kc.dump.query
		escape:function(){
			return escape(kc.dump.query);
		},
		//Unescape a kc.dump.query
		unescape:function(){
			return unescape(kc.dump.query);
	}}
	
	
	
	//==EVENT==//
	kc.proto.event={
		//Return target element (Element that triggered the event)
		target:function(){
			var e=kc.dump.event;
			var target;
			e.target ? target=e.target : target=e.srcElement;
			return target;
		},
		//Return event type
		type:function(){
			var e=kc.dump.event;
			var type=e.type;
			if(type=="DOMMouseScroll") type="mousewheel";
			return type;
		},
		//Cursor position
		cursor:function(axis){
			var e=kc.dump.event;
			var kccursorX=0;
			var kccursorY=0;
			var cursorPos=new Array();
			if(document.captureEvents){
				kccursorX=e.pageX;
				kccursorY=e.pageY;
				if(kccursorX<0) kccursorX=0;
				if(kccursorY<0) kccursorY=0;
			}else{
				kccursorX=e.clientX+document.body.scrollLeft;
				kccursorY=e.clientY+document.body.scrollLeft;
			}
			if(axis===undefined){
				return [kccursorX,kccursorY];
			}else{
				if(axis===0 || axis==="x") return kccursorX;
				if(axis===1 || axis==="y") return kccursorY;
			}
		},
		//Mouse wheel delta (if available)
		delta:function(){
			var e=kc.dump.event;
			var delta;
			if(e.wheelDelta) {
				delta=e.wheelDelta/120;
			}else if(e.detail) {
				delta=e.detail/3;
			}
			return delta;
		},
		//ALT key is pressed
		alt:function(){
			return kc.dump.event.altKey;
		},
		//CTRL key is pressed
		ctrl:function(){
			return kc.dump.event.ctrlKey;
		},
		//Keypress data
		key:function(){
			var e=kc.dump.event;
			var key;
			e.keyCode ? key=e.keyCode : key=e.charCode;
			return key;
		},
		//Prevent default
		prevent:function(bool){
			var e=kc.dump.event;
			try{e.preventDefault();}catch(err){e.returnValue=false;}
		},
		//Stop propagation
		stop:function(bool){
			var e=kc.dump.event;
			try{e.stopPropagation();}catch(err){e.cancelBubble=true;}
		}
	};
	
	
	
	//==FILE LOADING==//
	//proto.string extension
	kc.proto.string.load=function(a){
		var uri=kc.dump.query;
		var thisload={};
		if(a===undefined) var a={};
		
		//misc output
		a.uri=uri;
		if(a.method===undefined) a.method="GET";
		if(a.asynch===undefined) a.asynch=true;
		if(a.send===undefined) a.send=null;
		
		//load events
		if(a.onstart===undefined) a.onstart=function(){};
		if(a.onstatechange===undefined) a.onstatechange=function(){};
		if(a.onuninitialized===undefined) a.onuninitialized=function(){};
		if(a.onloading===undefined) a.onloading=function(){};
		if(a.onloaded===undefined) a.onloaded=function(){};
		if(a.oninteractive===undefined) a.oninteractive=function(){};
		if(a.oncomplete===undefined) a.oncomplete=function(){};
		
		//httpRequest object and response containers
		if(window.ActiveXObject) a.request = new ActiveXObject("Microsoft.XMLHTTP");
		if(window.XMLHttpRequest) a.request = new XMLHttpRequest();
		
		//executing file load
		var starttime=new Date();
		starttime=starttime.getTime();
		a.onstart();
		a.request.onreadystatechange=function(e){
			a.onstatechange();
			if(!e) e=window.event;
			a.event=e;
			try{a.response=a.request.responseText}catch(err){}
			var endtime=null;
			if(a.request.readyState==0){
				endtime=new Date();
				endtime=endtime.getTime();
				a.time=endtime-starttime;
				a.phase=0;
				a.phasename='uninitialized';
				a.onuninitialized();
			}else if(a.request.readyState==1){
				endtime=new Date();
				endtime=endtime.getTime();
				a.time=endtime-starttime;
				a.phase=1;
				a.phasename='loading';
				a.onloading();
			}else if(a.request.readyState==2){
				endtime=new Date();
				endtime=endtime.getTime();
				a.time=endtime-starttime;
				a.phase=2;
				a.phasename='loaded';
				a.onloaded();
			}else if(a.request.readyState==3){
				endtime=new Date();
				endtime=endtime.getTime();
				a.time=endtime-starttime;
				a.phase=3;
				a.phasename='interactive';
				a.oninteractive();
			}else if(a.request.readyState==4){
				endtime=new Date();
				endtime=endtime.getTime();
				a.time=endtime-starttime;
				a.phase=4;
				a.phasename='complete';
				a.oncomplete();
			}
		}
		if(a.method.toUpperCase()=="POST"){
			a.request.open(uri,a.asynch);
			a.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			a.request.send(a.send);
		}
		if(a.method.toUpperCase()=="GET"){
			a.request.open(a.method,uri+"?"+a.send,a.asynch);
			a.request.send(null);
		}
		thisload.output=a;
		return thisload;
	}
	
	
	
	
	//==CSS MANIPULATION==//
	//for string, number and undefined datatypes
	//Based on CSShepherd http://csshepherd.kaisarcode.com/
	kc.extend(['string','number','undefined'],{
		sheet:function(index){
			var selector=kc.dump.query;
			if(index===undefined) var index=kc.dump.filter;
			return CSShepherd(selector,index);
		}
	});
	/*
	CSShepherd v1.0
	"CSS in its stylesheet, all right with the world"
	*/
	var CSShepherd=function(selector,index){
		var kcobj={};
		var kcelemslength=0;
		var kcstylesheets=document.styleSheets;
		var kcsheetindex=[];
		
		//Set up needed functions
		var getDatatype=function(testelem){
			if(testelem===undefined) return "undefined";
			if(testelem===null) return "null";
			if(testelem.toString()=="NaN") return "nan";
			if(testelem.constructor){ 
				if(testelem.constructor.toString().toLowerCase().match("event")) return "event";
				if(testelem.constructor.toString().toLowerCase().match("object")) return "object";
				if(testelem.constructor.toString().toLowerCase().match("function")) return testelem.constructor.toString().split("function")[1].split("(")[0].replace(/^\s+|\s+$/g, '').toLowerCase();
				return "not-supported";
			} 
		}
		
		switch(typeof(selector)){
			case "undefined":
				for(var kci=0;kci<kcstylesheets.length;kci++){
					kcobj[kci]=kcstylesheets[kci];
					kcsheetindex.push(kci);
					kcelemslength++;
				}
			break;
			case "number":
				kcobj[0]=kcstylesheets[selector];
				if(kcstylesheets[selector]){
					kcsheetindex.push(selector);
					kcelemslength=1;
				}
			break;
			case "string":
				//select stylesheets by an attribute-value pair
				var kcsel=selector.replace(/(')|(")/g,"");
				var kcselattr=kcsel.split("=");
				var kcattr=kcselattr[0].replace(/^\s+|\s+$/g, '');
				var kcval=null;
				if(kcselattr[1]){
					kcval=kcselattr[1].replace(/^\s+|\s+$/g, '');
					var kcrx=new RegExp('\\b'+kcval+'\\b','g');
				}else{
					//If selector is just a simple string it matches this value against the href attribute,
					//in this case you could find a stylesheet called "style.css"
					kcval=kcattr;
					kcattr="href";
					var kcrx=new RegExp(kcval,'g');
				}
				var thisparent=null;
				var kccnt=0;
				for(var kci=0;kci<kcstylesheets.length;kci++){
					kcstylesheets[kci].owningElement ? thisparent=kcstylesheets[kci].owningElement : thisparent=kcstylesheets[kci].ownerNode;
					if(thisparent.attributes[kcattr]){
						if(thisparent.attributes[kcattr].value.match(kcrx)){
							if(index===undefined){
								kcobj[kcelemslength]=kcstylesheets[kci];
								kcsheetindex.push(kci);
								kcelemslength++;
							}else{
								if(kccnt===index){
									kcobj[0]=kcstylesheets[kci];
									kcsheetindex.push(kci);
								}
								kccnt++;
								kcelemslength=1;
							}
						}
					}
				}
			break;
		}
		//amount of result stylesheet
		kcobj.length=kcelemslength;
		//index position of the rule in the HTML stack
		kcobj.index=kcsheetindex;
		//selection Query
		kcobj.selector=selector;
		//Parent node (Owner node) of the stylesheet object
		kcobj.parent=function(){
			var kcparents={};
			var thisparent=null;
			var kccnt=0;
			for(var kci=0;kci<kcobj.length;kci++){
				kcobj[kci].owningElement ? thisparent=kcobj[kci].owningElement : thisparent=kcobj[kci].ownerNode;
				kcparents[kccnt]=thisparent;
				kccnt++;
			}
			return kcparents;
		}
		//returns the status or disables/enables a stylesheet
		kcobj.disabled=function(bool){
			var kcdisabled=[];
			for(var kci=0;kci<kcobj.length;kci++){
				if(bool===undefined){
					kcdisabled.push(kcobj[kci].disabled);
				}else{
					bool ? kcdisabled.push(kcobj[kci].disabled=true) : kcdisabled.push(kcobj[kci].disabled=false);
				}
			}
			return kcdisabled;
		}
		
		/*STYLESHEET RULES*/
		kcobj.rule=function(selector,index){
			kcrule={};
			var kcselector=[];
			var kccsstext=[];
			var crossrules=null;
			var rulelength=0;
			var ruleindex=[];
			var ruleparent={};
			if(selector!==undefined) var kcrx=new RegExp(selector,'g');
			function kcRuleSettings(){
				kcrule[rulelength]=crossrules[kcr];
				kcselector.push(kcrule[rulelength].selectorText);
				try{kcrule[rulelength].cssText ? kccsstext.push(kcrule[rulelength].cssText.split("{")[1].split("}")[0].replace(/^\s+|\s+$/g,'')) : kccsstext.push(kcrule[rulelength].style.cssText.replace(/^\s+|\s+$/g,''));}
				catch(err){kccsstext.push(undefined)}
				rulelength++;
				ruleindex.push(kcr);
				ruleparent[rulelength-1]=kcobj[kci];
			}
			for(var kci=0;kci<kcobj.length;kci++){
				kcobj[kci].cssRules ? crossrules=kcobj[kci].cssRules : crossrules=kcobj[kci].rules;
				if(selector===undefined){
					for(var kcr=0;kcr<crossrules.length;kcr++){
						kcRuleSettings();
					}
				}else{
					switch(typeof(selector)){
					case "number":
						for(var kcr=0;kcr<crossrules.length;kcr++){
							if(selector===kcr){
								kcRuleSettings();
							}
						}
					break;
					case "string":
						if(selector==":last"){
							kcr=crossrules.length-1;
							kcRuleSettings();
						}else{
							for(var kcr=0;kcr<crossrules.length;kcr++){
								if(crossrules[kcr].selectorText){
									if(crossrules[kcr].selectorText.toLowerCase().replace(/^\s+|\s+$/g,'').match(kcrx)){
										if(index===undefined){
											kcRuleSettings();
										}else{
											if(index===kccnt){
												kcRuleSettings();
											}
											kccnt++;
										}
									}
								}
							}
						}
					break;
					default:
					  return undefined;
					}
				}
			}
			//CSS Selector strings of the result rules
			kcrule.selector=kcselector;
			//CSS Declaration strings of the result rules
			kcrule.declaration=kccsstext;
			//Amount of result rules
			kcrule.length=rulelength;
			//Index position of each selected rule in the stylesheet
			kcrule.index=ruleindex;
			//Return the parent sheet
			kcrule.parent=ruleparent;
			//Return or edit the style object of a rule
			//you can also remove a style by passing null as value
			kcrule.style=function(kcproperty,kcvalue){
				var kcrules={};
				
				if(kcproperty!==undefined){
					if(typeof(kcproperty)=="string"){
						var decl_left=kcproperty.split("-");//transform the CSS properties name, into valid javaScript one
						for(var ditem=0;ditem<decl_left.length;ditem++){
							if(ditem>0){
								decl_left[ditem]=decl_left[ditem].charAt(0).toUpperCase() + decl_left[ditem].slice(1);//Instead of the dash , JS uses Camel Cased CSS declarations. here, we make that change.
							}
						}
						decl_left=decl_left.join("");//Now we join all together to construct the new JS valid css property
					}
				}
				
				for(var kcr=0;kcr<kcrule.length;kcr++){
					if(kcproperty===undefined){
						kcrules[kcr]=kcrule[kcr].style;
					}else{
						if(typeof(kcproperty)=="number"){
							kcrules[0]=kcrule[kcproperty].style;
						}else{
							if(kcvalue===undefined){
								kcrules[kcr]=kcrule[kcr].style[decl_left];
							}else{
								kcrules[kcr]=kcrule[kcr].style[decl_left]=kcvalue;
							}
						}
					}
				}
				return kcrules;
			}
			//Add styles to a rule
			kcrule.set=function(declaration){
				var kcrules={};
				var kcstyles;
				if(declaration===undefined){
					kcrules[kcr]=kcrule[kcr].style;
				}else{
					for(var kcr=0;kcr<kcrule.length;kcr++){
						if(typeof(declaration)=="string"){
							var each_decl=declaration.split(";");//we split the different declarations
							for(elem in each_decl){
								var decl_prop=each_decl[elem].split(":");//then we split each property-value pair
								var decl_left=decl_prop[0].split("-");//now, we have to transform the CSS properties names, to valid javaScript ones
								for(var ditem=0;ditem<decl_left.length;ditem++){
									if(ditem>0){
										decl_left[ditem]=decl_left[ditem].charAt(0).toUpperCase() + decl_left[ditem].slice(1);//Instead of the dash , JS uses Camel Cased CSS declarations. here, we make that change.
									}
								}
								decl_left=decl_left.join("");//Now we join all together to construct the new JS valid css property
								/* Finally, we apply the new styles */
								if(decl_prop[1]){
									for(var kcr=0;kcr<kcrule.length;kcr++){
										if(index===undefined){
											kcrule[kcr].style[decl_left]=decl_prop[1];
											kcrules[kcr]=kcrule[kcr];
										}else{
											if(index==kcr){
												kcrule[kcr].style[decl_left]=decl_prop[1];
												kcrules[kcr]=kcrule[kcr];
											}
										}
									}
								}
							}
						}else if(getDatatype(declaration)=="object"){
							for(kcstyles in declaration){
								kcrule[kcr].style[kcstyles]=declaration[kcstyles];
							}
							kcrules[kcr]=kcrule[kcr].style;
						}else{
							kcrules[kcr]=kcrule[kcr].style;
						}
					}
				}
				return kcrule.style();
			}
			//remove the rule
			kcrule.unset=function(){
				var kccnt=0;
				var oldparent=kcrule.parent[0];
				for(var kci=0;kci<kcrule.length;kci++){
					if(oldparent!==kcrule.parent[kci]){
						kccnt=0;
					}
					if(kcrule.parent[kci].deleteRule){
						kcrule.parent[kci].deleteRule(kcrule.index[kci]-kccnt);
					}else{
						kcrule.parent[kci].removeRule(kcrule.index[kci]-kccnt);
					}
					kccnt++;
					oldparent=kcrule.parent[kci];
				}
				return kcobj.rule();
			}
			//empty rule styles (doesn't removes the rule)
			kcrule.empty=function(propertyname){
				var decl_left;
				if(propertyname===undefined){
					for(kcs in kcrule.style()){
						decl_left=[];
						for(var kcd=0; kcd<kcrule.style()[kcs].length; kcd++){
							decl_left.push(kcrule.style()[kcs][kcd]);
						}
						for(var kcd=0;kcd<decl_left.length;kcd++){
							kcrule.style(decl_left[kcd],null);
						}
					}
				}else{
					kcrule.style(propertyname,null);
				}
				return kcrule.style();
			}
			return kcrule;
		}
		//add a new rule
		kcobj.add=function(selector,declaration,index){
			var kcruleselect;
			var kcruleindex;
			for(var kci=0;kci<kcobj.length;kci++){
				if(index===undefined){
					kcruleindex=CSShepherd(kci).rule().length;
					kcruleselect=":last";
				}else{
					kcruleselect=index;
					kcruleindex=index;
				}
				if(kcobj[kci].insertRule) kcobj[kci].insertRule(selector+"{ }",kcruleindex);
				if(kcobj[kci].addRule) kcobj[kci].addRule(selector," ",kcruleindex);
				
			}
			if(declaration!==undefined){
				kcobj.rule(kcruleselect).set(declaration);
			}
			return kcobj.rule(kcruleselect);
		}
		return kcobj;
	}
	/*END OF CSS MANIPULATION********************************************************************/
	
	
	
	
	
	//==HTML ELEMENTS MANIPULATION==//
	//For string, numbr, undefined and object datatypes
	//Based on KaisarCode selector
	kc.extend(['string','number','undefined','object'],{
		select:function(index){
			var selector=kc.dump.query;
			if(index===undefined) var index=kc.dump.filter;
			return kcSelect(selector,index);
		}
	});
	//KaisarCode Selector (extract)
	var selectByElem=function(elem,index,selector){
		var kcobj={};
		var testcontentlength=0;
		kcobj.length=0;
		kcobj.selector;
		if(elem!==undefined){
			//selector property/fallback
			selector===undefined ? kcobj.selector=elem : kcobj.selector=selector;
			if(elem[0]===undefined){
				var tmpelem=elem;
				elem={};
				elem[0]=tmpelem;
			}
			for(var elems in elem){
				kcobj[elems]=elem[elems];
				kcobj.length++;
			}
			/*STYLE: Retrieve or set inline styles on the result elements*/
			kcobj.style=function(property,value){
				var kcstyles={};
				var kccnt=0;
				if(property===undefined){
					for(var kci=0;kci<kcobj.length;kci++){
						if(kcobj[kci].attributes.style){
							kcstyles[kccnt]=kcobj[kci].style;
						}else{
							kcstyles[kccnt]=null;
						}
						kccnt++;
					}
				}else{
					for(var kci=0;kci<kcobj.length;kci++){
						if(typeof(property)=="object"){
							for(var prop in property){
								kcobj[kci].style[prop]=property[prop];
							}
						}else{
							if(value===undefined){
								if(kcobj[kci].attributes.style){
									return kcobj[kci].style[property];
								}else{
									return null;
								}
							}else{
								if(kcobj[kci].attributes.style){
									return kcobj[kci].style[property]=value;
								}else{
									kcobj[kci].setAttribute("style",property+":"+value+";");
									return kcobj[kci].style[property];
								}
							}
						}
						kcstyles[kci]=kcobj[kci].style;
					}
				}
				return kcstyles;
			}
			/*LISTEN: Add a new event listener for the result elements*/
			kcobj.listen=function(event_str,callback){
				for(var kci=0;kci<kcobj.length;kci++){
					if(document.addEventListener) {
						if(event_str=="mousewheel") kcobj[kci].addEventListener("DOMMouseScroll",callback);
						kcobj[kci].addEventListener(event_str,callback);
					}else{
						kcobj[kci].attachEvent('on'+event_str,callback);
					}
				}
				return kcobj;
			}
			/*POSITION: Return the absolute position on screen of each element in the result collection*/
			kcobj.position=function(axis){
				var kcpos=[];
				var kcposval=[];
				var kcelem=null;
				if(axis===undefined) axis=null;
				for(var kci=0;kci<kcobj.length;kci++){
					kcelem=kcobj[kci];
					kcposval[0]=0;
					kcposval[1]=0;
					do{
						kcposval[0]+=kcelem.offsetLeft;
						kcposval[1]+=kcelem.offsetTop;
					}while(kcelem=kcelem.offsetParent);
					if(axis===null) kcpos.push([kcposval[0],kcposval[1]]);
					if(axis==="x" || axis===0) kcpos.push(kcposval[0]);
					if(axis==="y" || axis===1) kcpos.push(kcposval[1]);
				}
				if(kcobj.length==1){
					if(axis===null) kcpos=[kcposval[0],kcposval[1]];
					if(axis==="x" || axis===0) kcpos=kcposval[0];
					if(axis==="y" || axis===1) kcpos=kcposval[1];
				}
				return kcpos;
			}
			/*SIZE: Return the absolute size of each element in the result collection*/
			kcobj.size=function(axis){
				var kcsize=[];
				var kcsizeval=[];
				var kcelem=null;
				if(axis===undefined) axis=null;
				for(var kci=0;kci<kcobj.length;kci++){
					kcelem=kcobj[kci];
					if(kcelem===document){
						/*Shortcut for document Height*/
						kcelem=document.documentElement;
					}
					kcsizeval[0]=kcelem.offsetWidth;
					kcsizeval[1]=kcelem.offsetHeight;
					
					if(axis===null) kcsize.push([kcsizeval[0],kcsizeval[1]]);
					if(axis==="width" || axis===0) kcsize.push(kcsizeval[0]);
					if(axis==="height" || axis===1) kcsize.push(kcsizeval[1]);
				}
				if(kcobj.length==1){
					if(axis===null) kcsize=[kcsizeval[0],kcsizeval[1]];
					if(axis==="width" || axis===0) kcsize=kcsizeval[0];
					if(axis==="height" || axis===1) kcsize=kcsizeval[1];
				}
				return kcsize;
			}
		}
		//checking if result is a fallback content
		for(var elems in kcobj[0]){testcontentlength++;}
		if(testcontentlength==0) kcobj.length=0;
		return kcobj;
	}
	//select HTML elements using CSS syntaxis
	var selectByCSS=function(selector,index){
		var kcobj={};
		var kccnt=0;
		var kcelemslength=0;
		if(document.querySelectorAll){
			var kcelems=document.querySelectorAll(selector);
			kcelemslength=kcelems.length;
			for(var kci=0;kci<kcelems.length;kci++){
				if(index===undefined){
					kcobj[kci]=kcelems[kci];
				}else{
					if(kci===index){
						kcobj[0]=kcelems[kci];
						kcelemslength=1;
					}
				}
			}
			kccnt=kcelemslength;
		}else{
			var kcdocall=document.all;
			var kcdummysheet = document.createStyleSheet();
			kcdummysheet.addRule(selector,"kc:kc");
			for(var kci=0;kci<kcdocall.length;kci++){
				if(kcdocall[kci].currentStyle.kc==="kc"){
					if(index===undefined){
						kcobj[kccnt]=kcdocall[kci];
						kccnt++;
						kcelemslength=kccnt;
					}else{
						if(kccnt===index){
							kcobj[0]=kcdocall[kci];
						}
						kccnt++;
						kcelemslength=1;
					}
				}
			}
			kcdummysheet=false;
		}
		return selectByElem(kcobj,undefined,selector);
	}
	//Select elements by a pair of attribute/value
	var selectByAttr=function(selector,index){
		var kcobj={};
		var kcsel=selector.replace(/(')|(")/g,"");
		var kcselattr=kcsel.split("=");
		var kcattr=kcselattr[0].replace(/^\s+|\s+$/g, '')
		var kcval="*";//if there's no value, value becomes an asterisk
		if(kcselattr[1]){
			kcval=kcselattr[1].replace(/^\s+|\s+$/g, '');
		}
		var kccnt=0;
		var kcelemslength=0;
		var docall=selectByCSS('*');
		for(var kci=0;kci<docall.length;kci++){
			if(docall[kci].attributes[kcattr]){
				if(kcval=="*"){
					kcobj[kccnt]=docall[kci];
					kccnt++;
				}else{
					var kcrx=new RegExp('\\b'+kcval+'\\b','g');
					if(docall[kci].attributes[kcattr].value.match(kcrx)){
						if(index===undefined){
							kcobj[kccnt]=docall[kci];
							kccnt++;
							kcelemslength=kccnt;
						}else{
							if(kccnt===index){
								kcobj[0]=docall[kci];
							}
							kccnt++;
							kcelemslength=1;
						}
					}
				}
			}
		}
		return selectByElem(kcobj,undefined,selector);
	}
	//Select elements by its HTML stack position
	var selectByIndex=function(num){
		var kcobj={};
		var kcresult=selectByCSS("*");
		var kcelemslength=0;
		for(var kci=0;kci<kcresult.length;kci++){
			if(kci===num){
				kcobj[0]=kcresult[kci];
				kcelemslength=1;
			}
		}
		return selectByElem(kcobj,undefined,num);
	}
	//Condensed method to select HTML elements, based on domcss and domattr functions
	var kcSelect=function(selector,index){
		if(selector===undefined) selector="*";
		if(typeof(selector)=="string"){
			//Select elements by attribute
			if(selector.match(/^\w+=[["[w+]|[w+\s+]+"]|['[w+]|[w+\s+]+']|[\*]]$/)){
				return selectByAttr(selector,index);
			}
			//Select elements by CSS syntaxis
			else{
				return selectByCSS(selector,index);
			}
		}
		//Select dom object
		else if(typeof(selector)=="object"){
			return selectByElem(selector,index);
		}
		//Select elements by html stack
		else if(typeof(selector)=="number"){
			return selectByIndex(selector,index);
		}
	}
	/*END OF HTML ELEMENTS MANIPULATION*******************************************************/
	
	
	//=== HTML5 DETECTION AND MANIPULATION ===//
	kc.html5={};
	/*
	 * @title: HTML5 Init
	 * @description: Initializes the new HTML5 tags for Internet Explorer 8 and minors
	 * @params: tag_names[Array] (Optional) - List of elements to initialize
	 * @return: success [Boolean]
	 * @example: kc.HTML5Init();
	*/
	kc.html5.init=function(tag_names){
		if(tag_names===undefined){
			var kc_HTML5_elements=[
			"article",
			"aside",
			"audio",
			"bdi",
			"canvas",
			"command",
			"datalist",
			"details",
			"embed",
			"figcaption",
			"figure",
			"footer",
			"header",
			"hgroup",
			"keygen",
			"mark",
			"meter",
			"nav",
			"output",
			"progress",
			"rp",
			"rt",
			"ruby",
			"section",
			"source",
			"summary",
			"time",
			"track",
			"video",
			"wbr"
			];
		}else{
			var kc_HTML5_elements=tag_names;
		}
		function kcCreateElement(kc_arr){
			for(kc_elem in kc_arr){
				document.createElement(kc_arr[kc_elem]);
			}
		}
		try{kcCreateElement(kc_HTML5_elements);return true}catch(err){return false;}
	}
	/*
	 * @title: detect HTML5 Features
	*/
	kc.html5.detect=function(featurename){
		switch(featurename){
		case "placeholder":
			var kcdummynode=document.createElement("input");
			typeof(kcdummynode.placeholder)=="string" ? kcdummynode=true : kcdummynode=false;
			return kcdummynode;
			break;
		case "contenteditable":
			var kcdummynode=document.createElement("div");
			typeof(kcdummynode.contenteditable)=="string" ? kcdummynode=true : kcdummynode=false;
			return kcdummynode;
			break;
		case "contextmenu":
			var kcdummynode=document.createElement("div");
			typeof(kcdummynode.contextmenu)=="string" ? kcdummynode=true : kcdummynode=false;
			return kcdummynode;
			break;
		case "draggable":
			var kcdummynode=document.createElement("div");
			typeof(kcdummynode.draggable)=="string" ? kcdummynode=true : kcdummynode=false;
			return kcdummynode;
			break;
		case "dropzone":
			var kcdummynode=document.createElement("div");
			typeof(kcdummynode.dropzone)=="string" ? kcdummynode=true : kcdummynode=false;
			return kcdummynode;
			break;
		case "hidden":
			var kcdummynode=document.createElement("div");
			typeof(kcdummynode.hidden)=="string" ? kcdummynode=true : kcdummynode=false;
			return kcdummynode;
			break;
		case "spellcheck":
			var kcdummynode=document.createElement("div");
			typeof(kcdummynode.spellcheck)=="string" ? kcdummynode=true : kcdummynode=false;
			return kcdummynode;
			break;
		case "audio":
			return "HTMLAudioElement" in window
			break;
		case "canvas":
			return "HTMLCanvasElement" in window
			break;
		case "command":
			return "HTMLCommandElement" in window
			break;
		case "embed":
			return "HTMLEmbedElement" in window
			break;
		case "keygen":
			return "HTMLKeygenElement" in window
			break;
		default:
		  return undefined;
		}
	}
	/*END OF HTML5 DETECTION AND MANIPULATION*****************************************************************/
	
})()
